OOP  - Assignment 3

Topic:              Huge Integer

Points: 25

Due:                2-3-2004

Instructor:      Dana Steil

Required Files:

HugeInteger.h

HugeInteger.cpp

Class Description:

Create a Class CHugeInteger that uses a string to represent large integers.  The class should be able to store any positive and negative numbers containing any number of characters.  Assume the integer is positive unless the first character is ‘-‘.   The following class definition or any equivalent is required.  Your HugeInteger will be tested by calling all of the public functions shown. Feel free to add functions and/or additional functionality.

 

class CHugeInteger

{

       public:

              //provide a default constructor that initializes the value to 0

              //provide constructor(s) to work with a string, long, and another CHugeInteger

 

              void Get();

              void Display() const;

 

              void Set(const string& NewValue);

              void Set(long NewValue);

              void Set(const CHugeInteger& NewValue);

 

              void Add(const string& Additive);

              void Add(long Additive);

              void Add(const CHugeInteger& Additive);

 

              void Subtract(const string& Subtractive);

              void Subtract(long Subtractive);

              void Subtract(const CHugeInteger& Subtractive);

 

              bool IsEqual(const string& Other) const;

              bool IsEqual(long Other) const;

              bool IsEqual(const CHugeInteger& Other) const;

 

       private:

              string m_Value;

 

              bool IsNumeric():

};

 

Provide a default constructor that initializes the value to 0.

 

Provide constructors to accept a string, long, or anotherCHugeInteger, as a parameter.  The HugeInteger should initialize its own value to this parameter.

 

The Get function should allow the user to input a value, validate that the value entered is numeric, and truncate any decimal positions.  If the value entered is not numeric set m_Value to “0”.  I realize that we could derive a method of picking a number out of the string but I want to keep this as simple as possible.

 

The Display function simply presents the value on the screen.   If you want to complicate the function, include commas after every third number (reading from right to left).

 

The Set functions should assign the value of their parameters to m_Value. 

 

The Subtract functions should subtract the value of the parameter from m_Value.

 

The Add functions should add the value of the parameter to m_Value.

 

The IsEqual functions should return true if parameter is the same value as m_Value.  It should return false otherwise.

 

The private IsNumeric function should return true if m_Value accurately represents an integer as describe above.  It should return false otherwise.  This function should be used from the public method Get.

Test Program:

You are responsible for providing a test program named Assignment2.cpp.  Your test program should test every function in the class definition.  I will also use a test program of my own on your class.

The string Data Type:

To use the string datatype use the following includes and using declarations.

 

#include<iostream>

#include<string>

 

using std::cout;

using std::cin;

using std::string;

 

Tips:

For an example on how to use the string data-type see:

http://www.harding.edu/dsteil/345/examples/string_example.cpp

 

For an example of how to convert a long to a string see:

http://www.harding.edu/dsteil/345/examples/ltoa example.cpp

 

For an example of how to convert all of a string to a long, or part of a string to a long see:

http://www.harding.edu/dsteil/345/examples/atol example.cpp